package com.niit.springbootshop.controller;

import com.niit.springbootshop.entity.Product;
import com.niit.springbootshop.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @program: springboot-demo
 * @description:
 * @author: hanliang
 * @create: 2021-05-07 15:08
 **/
@Controller
public class ProductController {

    @Autowired
    ProductService productService;


    @RequestMapping("/getNewProducts")
    @ResponseBody
    public List<Product> getNewProducts(){
        // 默认的数据格式，JSON格式
        // JSON 数据格式
        return productService.getNewProducts();
    }

    @RequestMapping("/goDetails")
    public String goDetails(ModelMap map,Integer pid){

        // 根据查询的pid查询商品信息
        map.addAttribute("p",productService.selectByPrimaryKey(pid));
        // 默认的数据格式，JSON格式
        // JSON 数据格式
        return "details";
    }
}
